package com.thiswhyme.common.utils.json.gson.strategy;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;

import java.lang.annotation.Annotation;

/**
 * @description: 排除策略，允许序列化和反序列化时，忽略标注了Ignore的属性的策略。
 * @author: thiswhyme
 * @date: 2020/9/17
 */
public class IgnoreAnnotationExclusionStrategy implements ExclusionStrategy {

    @Override
    public boolean shouldSkipField(FieldAttributes fieldAttr) {
        for (Annotation anno : fieldAttr.getAnnotations()) {
            if (anno.annotationType() == Ignore.class) {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean shouldSkipClass(Class<?> clazz) {
        return false;
    }
}